package com.ww.springboot.mybatis.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ww.springboot.mybatis.entity.Propagation2Entity;
import com.ww.springboot.mybatis.entity.PropagationEntity;
import com.ww.springboot.mybatis.mapper.Propagation2Mapper;
import com.ww.springboot.mybatis.mapper.PropagationMapper;
import com.ww.springboot.mybatis.service.IPropagation2Service;
import com.ww.springboot.mybatis.service.IPropagationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2022-10-17 18:16
 */
@Service
public class Propagation2ServiceImpl extends ServiceImpl<Propagation2Mapper, Propagation2Entity> implements IPropagation2Service {


    /**
     * 默认 Propagation.REQUIRED
     * Propagation.REQUIRES_NEW :重开一个事务 此子事务不影响主事务;子事务回滚 主事务不受影响
     * Propagation.NOT_SUPPORTED : 不加入主事务 且自己也不开启事务 即使有异常也可以不回滚
     *
     * @param flag2
     */
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void test(Boolean flag2) {
        Propagation2Entity propagation2Entity = new Propagation2Entity();
        propagation2Entity.setA("2A");
        propagation2Entity.setB("2B");
        propagation2Entity.setId(IdWorker.getId());
        this.save(propagation2Entity);
        if (flag2) {
            throw new RuntimeException("事务2 异常!");
        }
    }
}
